package com.example.yiwei.crm.view.frament.menuFragment;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.view.activity.coordinationActivity.UpdatePasswordActivity;
import com.example.yiwei.crm.view.activity.menuActivity.LoginActivity;


/**
 * Created by DHN on 2016/12/2.
 */
//个人界面
public class personal_information_fragment extends Fragment {
    TextView txt_name,txt_zhanghao,txt_phone,txt_job,txt_department;
    LinearLayout linearLayout_out,linearLayout_update;
    private SharedPreferences sp;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootview=inflater.inflate(R.layout.frament_fifth,container,false);
        txt_name= (TextView) rootview.findViewById(R.id.me_txt_name);
        txt_zhanghao= (TextView) rootview.findViewById(R.id.me_txt_zhanghao);
        txt_job= (TextView) rootview.findViewById(R.id.me_job);
        txt_department= (TextView) rootview.findViewById(R.id.me_department);
        linearLayout_out= (LinearLayout) rootview.findViewById(R.id.me_out);
        linearLayout_update= (LinearLayout) rootview.findViewById(R.id.me_update_password);
        sp = getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);
        txt_name.setText(sp.getString("UAB03",null));
        txt_zhanghao.setText(sp.getString("UAC02",null));
        txt_department.setText(sp.getString("UAA03",null));
        if (sp.getString("UAB06",null).equals("1")){
            txt_job.setText("总经理");
        }else if (sp.getString("UAB06",null).equals("2")){
            txt_job.setText("总监");
        }else if (sp.getString("UAB06",null).equals("3")){
            txt_job.setText("副总监");
        }else if (sp.getString("UAB06",null).equals("4")){
            txt_job.setText("总监助理");
        }else if (sp.getString("UAB06",null).equals("10")){
            txt_job.setText("健教组长");
        }else if (sp.getString("UAB06",null).equals("11")){
            txt_job.setText("健教组员");
        }else if (sp.getString("UAB06",null).equals("12")){
            txt_job.setText("健教助理");
        }else if (sp.getString("UAB06",null).equals("13")){
            txt_job.setText("健教主任");
        }else if (sp.getString("UAB06",null).equals("20")){
            txt_job.setText("区域主任");
        }else if (sp.getString("UAB06",null).equals("21")){
            txt_job.setText("区域主管");
        }else if (sp.getString("UAB06",null).equals("22")){
            txt_job.setText("协作接待");
        }else if (sp.getString("UAB06",null).equals("30")){
            txt_job.setText("集团客服组长");
        }else if (sp.getString("UAB06",null).equals("31")){
            txt_job.setText("集团客服组员");
        }else if (sp.getString("UAB06",null).equals("32")){
            txt_job.setText("主编");
        }else if (sp.getString("UAB06",null).equals("33")){
            txt_job.setText("设计");
        }else if (sp.getString("UAB06",null).equals("34")){
            txt_job.setText("编辑");
        }else if (sp.getString("UAB06",null).equals("35")){
            txt_job.setText("网络组长");
        }else if (sp.getString("UAB06",null).equals("36")){
            txt_job.setText("网络组员");
        }else if (sp.getString("UAB06",null).equals("40")){
            txt_job.setText("院内导诊");
        }else if (sp.getString("UAB06",null).equals("50")){
            txt_job.setText("院内客服组长");
        }else if (sp.getString("UAB06",null).equals("51")){
            txt_job.setText("院内客服组员");
        }else if (sp.getString("UAB06",null).equals("52")){
            txt_job.setText("院内数据专员");
        }else if (sp.getString("UAB06",null).equals("53")){
            txt_job.setText("院内客服主任");
        }
        linearLayout_out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.custom_dialog));
                builder.setTitle("您确定要退出吗？");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SharedPreferences.Editor editor = sp.edit();
                        editor.putString("password",null);
                        editor.commit();
                        Intent intent=new Intent(getActivity(), LoginActivity.class);
                        intent.putExtra("tag","exit");
                        startActivity(intent);
                        System.exit(0);
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();

            }
        });
        linearLayout_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Intent intent=new Intent(getActivity(), UpdatePasswordActivity.class);
                startActivity(intent);
                getActivity().finish();
            }
        });
        return rootview;
    }
}
